package test.enba.mq.producer.controller.rabbitmq.direct;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectExchangeConfig {

  // 定义直连交换器
  @Bean
  public DirectExchange directExchange() {
    return new DirectExchange("direct-exchange");
  }

  // 定义队列
  @Bean
  public Queue directQueue() {
    return new Queue("direct-queue");
  }

  // 绑定队列到交换器，并指定路由键
  @Bean
  public Binding directBinding(DirectExchange directExchange, Queue directQueue) {
    return BindingBuilder.bind(directQueue).to(directExchange).with("direct.routing.key");
  }
}
